<template>
  <div class="navbar">
    <Navbar>
      <div slot="left" class="arrow">
        <van-icon name="arrow-left" size="20px" @click="back" />
      </div>
      <div class="title" slot="center">
        <div
          v-for="(item, index) in titles"
          :key="index"
          @click="ChangeColor(index)"
          :class="{ active: index === currentIndex }"
          >{{ item }}</div
        >
      </div>
    </Navbar>
  </div>
</template>

<script>
import Navbar from "@/components/navbar";

import Vue from "vue";
import { Icon } from "vant";

Vue.use(Icon);

export default {
  name: "",
  components: {
    Navbar,
  },
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0,
    };
  },
  methods: {
    // 监听
    ChangeColor(index) {
      this.currentIndex = index;
      this.$emit("titleClick", index);
    },
    back() {
      this.$router.back();
    },
  },
};
</script>

<style scoped>
#navbar {
  background-color: #fff;
  position: fixed;
  top: 0;
}

.title {
  width: 100%;
  display: flex;
  justify-content: space-around;
  color: #646566;
  font-size: 14px;
}

.active {
  color: #f77;
}

.arrow {
  margin-left: 10px;
}
</style>